package org.particlethink.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import org.particlethink.entry.PlanStatus;
import org.particlethink.model.MasterPlan;
import org.particlethink.model.MasterPlanCategory;
import org.particlethink.model.Project;
import org.particlethink.model.ProjectUser;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.Optional;

public class MasterPlanResponse {
    @Schema(description = "id")
    private Integer id;
    @Schema(description = "项目")
    private ProjectResponse project;
    @Schema(description = "总计划单号")
    private String no;
    @Schema(description = "总计划大类")
    private MasterPlanCategoryResponse category;
    @Schema(description = "批次计划数量")
    private Integer batchPlanCount;
    @Schema(description = "提交人")
    private ProjectUserResponse submitUser;//提交人
    @Schema(description = "提交时间")
    private Date submitAt;//提交时间
    @Schema(description = "状态")
    private PlanStatus status;
    @Schema(description = "备注")
    private String remark;//备注


    @Schema(description = "创建人")
    private ProjectUserResponse createUser;//创建人
    @Schema(description = "创建时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
//    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createAt;//提交时间
    @Schema(description = "附件")
    private AttachmentResponse attachment;//附件


    public MasterPlanResponse() {
    }

    public MasterPlanResponse(
            MasterPlan masterPlan,
            Project project,
            MasterPlanCategory category,
            ProjectUser submitUser,
            ProjectUser createUser
    ) {
        this.id = masterPlan.getId();
        this.no = masterPlan.getNo();
        this.project = new ProjectResponse(Optional.ofNullable(project).orElseGet(Project::new));
        this.category = new MasterPlanCategoryResponse(Optional.ofNullable(category).orElseGet(MasterPlanCategory::new));

        this.batchPlanCount = masterPlan.getBatchPlanCount();
        this.submitUser = submitUser == null ? null : new ProjectUserResponse(submitUser);
        this.createUser = createUser == null ? null : new ProjectUserResponse(createUser);
        this.submitAt = masterPlan.getSubmitAt();
        this.status = masterPlan.getStatus();
        this.remark = masterPlan.getRemark();
        this.attachment = new AttachmentResponse(masterPlan.getAttachmentName(), masterPlan.getAttachment());
        this.createAt = masterPlan.getCreatedAt();
    }


    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public PlanStatus getStatus() {
        return status;
    }

    public void setStatus(PlanStatus status) {
        this.status = status;
    }

    public Date getSubmitAt() {
        return submitAt;
    }

    public void setSubmitAt(Date submitAt) {
        this.submitAt = submitAt;
    }


    public void setBatchPlanCount(int batchPlanCount) {
        this.batchPlanCount = batchPlanCount;
    }


    public ProjectResponse getProject() {
        return project;
    }

    public void setProject(ProjectResponse project) {
        this.project = project;
    }


    public void setId(int id) {
        this.id = id;
    }

    public ProjectUserResponse getSubmitUser() {
        return submitUser;
    }

    public void setSubmitUser(ProjectUserResponse submitUser) {
        this.submitUser = submitUser;
    }

    public ProjectUserResponse getCreateUser() {
        return createUser;
    }

    public void setCreateUser(ProjectUserResponse createUser) {
        this.createUser = createUser;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public MasterPlanCategoryResponse getCategory() {
        return category;
    }

    public void setCategory(MasterPlanCategoryResponse category) {
        this.category = category;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getBatchPlanCount() {
        return batchPlanCount;
    }

    public void setBatchPlanCount(Integer batchPlanCount) {
        this.batchPlanCount = batchPlanCount;
    }

    public AttachmentResponse getAttachment() {
        return attachment;
    }

    public void setAttachment(AttachmentResponse attachment) {
        this.attachment = attachment;
    }
}

